import { _decorator, Component, Node, Label, Input, EventTouch, Vec3, RichText } from 'cc';
const { ccclass, property } = _decorator;

import { losChannel } from "../SDK/losChannel";

@ccclass('LosPrivacyWin')
export default class losPrivacyWin extends Component {
    @property(Node)
    txt_main: Node | null = null;
    @property(Node)
    bt_agree: Node | null = null;
    @property(Node)
    bt_reject: Node | null = null;
    @property(Node)
    win2: Node | null = null;
    @property(RichText)
    txt: RichText | null = null;
    @property(Node)
    bt_next: Node | null = null;
    @property(Node)
    bt_pre: Node | null = null;
    @property(Node)
    close: Node | null = null;
    @property(Node)
    bt_type1: Node | null = null;
    @property(Node)
    bt_type2: Node | null = null;
    //    /** 隐私政策还是用户协议,0为前者，1为后者 */
    pType: number = 0;
    onLoad() {

        this.bt_type1.active = true
        this.bt_type2.active = true
        this.close.on(Input.EventType.TOUCH_END, (event: EventTouch) => {
            this.closeDetail();
        });

        this.bt_pre.on(Input.EventType.TOUCH_END, (event: EventTouch) => {
            this.txt.string = losChannel.instance().privacyPrePage(this.pType);
        });

        this.bt_next.on(Input.EventType.TOUCH_END, (event: EventTouch) => {
            this.txt.string = losChannel.instance().privacyNextPage(this.pType);
        });

        this.bt_type1.on(Input.EventType.TOUCH_END, (event: EventTouch) => {
            this.pType = 0;
            this.txt.string = losChannel.instance().privacyPage1(this.pType);
        });
        this.bt_type2.on(Input.EventType.TOUCH_END, (event: EventTouch) => {
            this.pType = 1;
            this.txt.string = losChannel.instance().privacyPage1(this.pType);
        });


        this.txt.string = losChannel.instance().privacyPage1(this.pType);

        // this.bt_agree.on(Input.EventType.TOUCH_END, (event: EventTouch) => {
        //     this.agree();
        // });

        // this.bt_reject.on(Input.EventType.TOUCH_END, (event: EventTouch) => {
        //     this.node.active = false;
        //     losChannel.instance().privacyReject();
        //     losChannel.instance().exit();
        // });

        this.txt_main.getComponent(RichText).string =
            `<color=#000000>欢迎您进入《${losChannel.instance().getGameName()}》，我们非常重视您的个人信息和隐私保护。为更好地保障您的个人权益，请您仔细阅读我们的<color=#009EFF>《用户服务协议》</c>和<color=#009EFF>《隐私政策》</c>。通过这些条款您可以了解我们如何收集、使用、保护和管理这些信息。点击“同意”即表示您已阅读完毕并同意上述协议和政策中的全部内容。</c>`
        this.txt_main.on(Input.EventType.TOUCH_END, (event: EventTouch) => {
            this.win2.active = true;
        });
        this.win2.active = false;
    }
    closeDetail() {
        this.win2.active = false;
    }
    protected onDisable(): void {
        this.bt_agree.off(Input.EventType.TOUCH_END)
        this.bt_reject.off(Input.EventType.TOUCH_END)
    }
    public showAsyn(onlyCheck = false): Promise<boolean> {
        this.node.parent.active = true;
        return new Promise((resolve) => {
            let newPosition = new Vec3(this.bt_agree.position.x, this.bt_agree.position.y, this.bt_agree.position.z);
            newPosition.x = 130;
            this.bt_agree.setPosition(newPosition);

            this.bt_reject.active = true
            let text = this.bt_agree.getChildByName("New Label").getComponent(Label)
            text.string = "同意"
            if (onlyCheck) {
                //隐藏拒绝按钮
                this.bt_reject.active = false
                //同意按钮居中
                newPosition.x = 0;
                this.bt_agree.setPosition(newPosition);
                text.string = "确定"
            }
            this.bt_agree.on(Input.EventType.TOUCH_END, (event: EventTouch) => {
                this.node.parent.active = false;
                losChannel.instance().privacyAgree();
                resolve(true)
            });

            this.bt_reject.on(Input.EventType.TOUCH_END, (event: EventTouch) => {
                this.node.parent.active = false;
                losChannel.instance().privacyReject();
                resolve(false)
                losChannel.instance().exit();
            });
        })
    }
}


/**
 * 注意：已把原脚本注释，由于脚本变动过大，转换的时候可能有遗落，需要自行手动转换
 */
// import { losChannel } from "../SDK/losChannel";
// import loskc from "../SDK/loskc";
// 
// 
// const { ccclass, property } = cc._decorator;
// 
// @ccclass
// export default class losPrivacyWin extends cc.Component {
// 
// 
//     @property(cc.Node)
//     txt_main: cc.Node = null;
//     @property(cc.Node)
//     bt_agree: cc.Node = null;
//     @property(cc.Node)
//     bt_reject: cc.Node = null;
//     @property(cc.Node)
//     win2: cc.Node = null;
// 
//     @property(cc.Label)
//     txt: cc.Label = null;
//     @property(cc.Node)
//     bt_next: cc.Node = null;
//     @property(cc.Node)
//     bt_pre: cc.Node = null;
//     @property(cc.Node)
//     close: cc.Node = null;
//     @property(cc.Node)
//     bt_type1: cc.Node = null;
//     @property(cc.Node)
//     bt_type2: cc.Node = null;
// 
// 
//     /** 隐私政策还是用户协议,0为前者，1为后者 */
//     pType: number = 0;
// 
//     onLoad() {
// 
//         this.bt_type1.active = true
//         this.bt_type2.active = false
//         this.close.on(Input.EventType.TOUCH_END, (event: EventTouch) => {
//             this.closeDetail();
//         });
// 
//         this.bt_pre.on(Input.EventType.TOUCH_END, (event: EventTouch) => {
//             this.txt.string = losChannel.instance().privacyPrePage(this.pType);
//         });
// 
//         this.bt_next.on(Input.EventType.TOUCH_END, (event: EventTouch) => {
//             this.txt.string = losChannel.instance().privacyNextPage(this.pType);
//         });
// 
//         this.bt_type1.on(Input.EventType.TOUCH_END, (event: EventTouch) => {
//             this.pType = 0;
//             this.txt.string = losChannel.instance().privacyPage1(this.pType);
//         });
//         this.bt_type2.on(Input.EventType.TOUCH_END, (event: EventTouch) => {
//             this.pType = 1;
//             this.txt.string = losChannel.instance().privacyPage1(this.pType);
//         });
// 
// 
//         this.txt.string = losChannel.instance().privacyPage1(this.pType);
// 
//         // this.bt_agree.on(Input.EventType.TOUCH_END, (event: EventTouch) => {
//         //     this.agree();
//         // });
// 
//         // this.bt_reject.on(Input.EventType.TOUCH_END, (event: EventTouch) => {
//         //     this.node.active = false;
//         //     losChannel.instance().privacyReject();
//         //     losChannel.instance().exit();
//         // });
// 
//         this.txt_main.on(Input.EventType.TOUCH_END, (event: EventTouch) => {
//             this.win2.active = true;
//         });
//         this.win2.active = false;
//     }
// 
//     closeDetail() {
//         this.win2.active = false;
//     }
//     protected onDisable(): void {
//         this.bt_agree.off(Input.EventType.TOUCH_END)
//         this.bt_reject.off(Input.EventType.TOUCH_END)
//         losChannel.instance().closeBanner()
//     }
//     public showAsyn(onlyCheck = false): Promise<boolean> {
//         this.node.parent.active = true;
// 
//         return new Promise((resolve) => {
//             this.bt_agree.x = 130
//             this.bt_reject.active = true
//             let text = this.bt_agree.getChildByName("New Label").getComponent(cc.Label)
//             text.string = "同意"
//             if (onlyCheck) {
//                 //隐藏拒绝按钮
//                 this.bt_reject.active = false
//                 //同意按钮居中
//                 this.bt_agree.x = 0
//                 text.string = "确定"
//             }
//             this.bt_agree.on(Input.EventType.TOUCH_END, (event: EventTouch) => {
//                 this.node.parent.active = false;
//                 losChannel.instance().privacyAgree();
//                 resolve(true)
//             });
// 
//             this.bt_reject.on(Input.EventType.TOUCH_END, (event: EventTouch) => {
//                 this.node.parent.active = false;
//                 losChannel.instance().privacyReject();
//                 resolve(false)
//                 losChannel.instance().exit();
//             });
//         })
//     }
// }
